This invention relates generally to concurrent programming, and more particularly to implementing process thread locking in a concurrent computing environment.
In a concurrent programming environment that utilizes multiple threads within a single process, there is a need to synchronize access among the threads to a shared object. To facilitate synchronization, one current solution uses a field called “lock word” that is stored in a header section of the shared object (e.g., the field indicating whether a lock has been acquired for the object). In this solution, a thread synchronizes access to the shared object by performing an atomic test-and-set operation on the lock word. A test-and-set operation refers to an instruction used by a thread to test and/or write to a memory location as part of a single atomic (non-interruptible) operation. However, in this solution, if the thread releases the storage used for the shared object, the lock may no longer be queried by other threads in the process and test-and-set operations may have unknown effects that could be potentially catastrophic for a system. Furthermore, the use of test-and-set operations prevents a thread from recursively locking the shared object. For example, depending on the implementation of the test-and-set operation, multiple attempts by a single thread to lock the same shared object may result in the thread blocking itself or a system error.
Another locking mechanism called a “mutex” is also used by threads to lock a shared object in order to facilitate recursive locking and, similar to the lock word, it is typically stored in the shared object itself in order to uniquely associate the mutex with the shared object. Similar to the test-and-set operation, the use of a mutex requires guaranteed access to the storage backing the shared object and its results can be hazardous to the system if the storage is not valid.
What is needed, therefore, is a way to provide recursive thread locking of shared objects that eliminates the potential for a thread blocking itself.